<template>
	<view class="user">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				我的
			</view>
		</view>
		<view class="headtop clearfix" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="left fl">
				<image :src="agent_image"></image>
			</view>
			<view class="right fl">
				<view class="name">{{nickname}}</view>
				<view class="desc">ID:{{id}} Tell:{{mobile}}</view>
			</view>
			<view class="shezhi" v-if="role_id != 1" @click="topage('/subpackageA/user/second/zhanghao?bussinid=' + agent_id)">
				<image :src="baseUrl + '/wximage/shezhi.png'"></image>
			</view>
		</view>
		<view class="nr">
			<view class="list clearfix" @click="topage('/subpackageA/user/fund/index')">
				<image :src="baseUrl + '/wximage/wodetb2.png'" class="tubiao fl"></image>
				<view class="title fl">资金管理</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
			<view class="list clearfix" @click="topage('/subpackageA/user/second/help')">
				<image :src="baseUrl + '/wximage/wodetb3.png'" class="tubiao fl"></image>
				<view class="title fl">常见问题</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
			<view class="list clearfix" @click="topage('/subpackageA/user/second/savepass')">
				<image :src="baseUrl + '/wximage/wodetb4.png'" class="tubiao fl"></image>
				<view class="title fl">修改密码</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
			<view class="list clearfix" @click="topage('/subpackageA/user/second/savetell')" v-if="role_id != 12">
				<image :src="baseUrl + '/wximage/wodetb5.png'" class="tubiao fl"></image>
				<view class="title fl">修改手机号</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
			<view class="list clearfix" @click="topage('/subpackageA/user/second/fankuilist')">
				<image :src="baseUrl + '/wximage/wodetb6.png'" class="tubiao fl"></image>
				<view class="title fl">反馈中心</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
			<view class="list clearfix" @click="topage('/subpackageA/user/second/article?id=14')">
				<image :src="baseUrl + '/wximage/wodetb7.png'" class="tubiao fl"></image>
				<view class="title fl">关于我们</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
			<view class="list clearfix" @click="tuichu">
				<image :src="baseUrl + '/wximage/wodetb8.png'" class="tubiao fl"></image>
				<view class="title fl">退出登录</view>
				<image :src="baseUrl + '/wximage/right.png'" class="you fr"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				agent_id: '',
				role_id: '',
				id: '',
				nickname: '',
				mobile: '',
				agent_image: '',
			}
		},
		created() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			// 用户信息
			this.agent_id = uni.getStorageSync('agent_id');
			this.role_id = uni.getStorageSync('role_id');
			
			this.request({
				url: '/agent/users',
				data: {
					id: this.agent_id,
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					if(res.data.data.delete_status == 2){
						uni.showModal({
							title: '提示',
							content: '您的账号已被封禁,请联系管理员',
							success: function (res) {
								if (res.confirm) {
									uni.setStorageSync('agent_id');
									uni.setStorageSync('role_id');
									uni.showToast({
										title: '退出成功',
										icon: 'none'
									})
									setTimeout(function(){
										uni.reLaunch({
											url: '/pages/index/index'
										})
									},2000)
								} else if (res.cancel) {
									uni.setStorageSync('agent_id');
									uni.setStorageSync('role_id');
									uni.showToast({
										title: '退出成功',
										icon: 'none'
									})
									setTimeout(function(){
										uni.reLaunch({
											url: '/pages/index/index'
										})
									},2000)
								}
							}
						})
					}else{
						this.id = res.data.data.id;
						this.nickname = res.data.data.nickname;
						this.mobile = res.data.data.mobile;
					}
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
			
			//获取基本配置信息
			this.request({
				url: '/xcx/webconfig',
				data: {}
			}).then(res => {
				if (res.data.code == 200) {
					this.agent_image = res.data.data.agent_image;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
		},
		methods: {
			//退出登录
			tuichu(){
				uni.showModal({
					title: '是否切换账号',
					content: '将会解绑当前账号!!!',
					success: function(res) {
						if (res.confirm) {
							uni.setStorageSync('agent_id');
							uni.setStorageSync('role_id');
							uni.showToast({
								title: '退出成功',
								icon: 'none'
							})
							setTimeout(function() {
								uni.reLaunch({
									url: '/pages/index/index'
								})
							}, 2000)
						} else if (res.cancel) {
				
						}
					}
				})
			},
			topage(url){
				uni.navigateTo({
					url
				})
			},
			fanhui() {
				uni.navigateBack();
			},
			kaifa() {
				uni.showToast({
					title: '暂未开放',
					icon: 'none'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.user {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: center;
				color: #333333;
				font-size: 32rpx;

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 20rpx 0;
			box-sizing: border-box;
			
			.left{
				
				image{
					width: 150rpx;
					height: 150rpx;
					border-radius: 50%;
				}
			}
			
			.right{
				margin-left: 20rpx;
				
				.name{
					font-size: 32rpx;
					color: #333333;
					font-weight: 700;
					margin-top: 30rpx;
				}
				
				.desc{
					font-size: 24rpx;
					color: #999999;
					margin-top: 20rpx;
				}
			}
			
			.shezhi{
				position: absolute;
				top: 200rpx;
				right: 40rpx;
				
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
		}
		
		.nr{
			width: 100%;
			margin: 0 auto;
			margin-top: -120rpx;
			padding: 40rpx 60rpx 40rpx 50rpx;
			box-sizing: border-box;
			
			.list{
				width: 100%;
				height: 56rpx;
				line-height: 56rpx;
				margin-bottom: 40rpx;
				
				.tubiao{
					width: 56rpx;
					height: 56rpx;
				}
				
				.title{
					font-size: 28rpx;
					color: #333333;
					font-weight: 700;
					margin-left: 14rpx;
				}
				
				.you{
					width: 30rpx;
					height: 30rpx;
					margin-top: 12rpx;
				}
			}
		}
	}
</style>